package bit_exercises.Day25;

/**
 * @author zerorain
 * @date 2022/05/23 21:29
 **/
import java.util.*;
//第一题 星际密码
//第二题 树根   没做出来 返回非零
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
                long n = sc.nextLong();
                while (Treeben(n) >= 10) {
                    n = Treeben(n);
                }
                System.out.println(Treeben(n));
            }
    }
    public static long Treeben(long n){
        long count = 0;
        while(n != 0){
            count = count + (n % 10);
            n = n / 10;
        }
        return count;
    }
}